<?
//xna
DEFINE("_ROOT",".");
include  _ROOT."/mainfile.php";
include _ROOT."/class/functions.php";
$is_run = $_COOKIE["is_run"];
if($is_run!='yes'){
	$is_run='no';
	setcookie("is_run","yes");
}
$cate = is_numeric( $_GET[cate] )  ? $_GET[cate] : "";
if(!in_array($cate,array_keys($rss_cate))) $cate="";
$arg = $cate>"" ? " and x.rss_cate='$cate' " : "";
$xnadb = $PlusDB->prefix("xna");
$xnanewsdb = $PlusDB->prefix("xna_news");
$cate_ids = implode(",",array_keys($rss_cate));
$date = $_GET["date"]?$_GET["date"]:"";
if($date>""){
	$ts =strtotime($date);
	$sd =  date("Y-m-d",$ts);
	$ed =  date("Y-m-d",$ts+24*60*60);
	$arg .= " and  n.ctime<'$ed' and n.ctime>='$sd' ";
}else{
	$arg  .= "";
}
$sql="select count(*) as sum ,rss_cate from $xnadb where rss_cate in ($cate_ids) group by rss_cate ";
//echo "$sql";
$rt = $PlusDB->execute($sql);
while($crow = $rt->fetchRow()){
	$cates[$crow[rss_cate]][id]=$crow[rss_cate];
	$cates[$crow[rss_cate]][name]=$rss_cate[$crow[rss_cate]];
	$cates[$crow[rss_cate]][sum]=$crow[sum];
}
$start = $_GET["start"];
$start = empty($start)?0:$start;
$sql="select count(*)  from $xnanewsdb n left join $xnadb x on (x.id=n.site_id) where 1 $arg";
$num = $PlusDB->getone($sql);
$start = ($start>$num)?0:$start;
$page = 300;
$xtime = time()-24*60*60;
$xtime=date("Y-m-d",$xtime);
include _ROOT."/class/page.inc.php";

//$sql="select *,n.ctime as ctime,n.id as id  from $xnanewsdb n left join $xnadb x on (x.id=n.site_id) where 1 $arg order by n.ctime desc ";
//$sql="select *,n.ctime as ctime,n.id as id  from $xnanewsdb n left join $xnadb x on (x.id=n.site_id) where  DATE_ADD(n.ctime,  INTERVAL 24 HOUR) > NOW()";
$sql="select *,n.ctime as ctime,n.id as id  from $xnanewsdb n left join $xnadb x on (x.id=n.site_id) where 1 and n.ctime>'$xtime' $arg order by n.ctime desc ";
//echo "$sql";
$rt = $PlusDB->SelectLimit($sql,$page,$start);
while($row = $rt->fetchRow()){
	$row[e_title] = urlencode($row[news_title]);
	$row[author] =$row[author]==""?$row[site_name]:$row[author];
	$n++;
	$row["n"]=$n;
	$ret[]=$row;
}
$vr = array("cate"=>$cate);
$ico=channelFavicon($rss->channel['link']) ;
$smarty->assign("list",$ret);
$smarty->assign("page",$page_break);
$smarty->assign("rss_cate",$cates);
$smarty->assign("is_run",$is_run);
$smarty->display("template/default/spvrk.tpl");
?>